uniform vec3 env_skyColor1;
uniform vec3 env_skyColor2;
uniform vec3 env_cameraPos;
uniform float env_visualRange;
uniform float env_fogLength;
uniform sampler2D tex_cloud1;

varying vec3 _position;
varying vec2 _texture;

void main(void) {

	float dist = distance(_position.xz * env_visualRange, vec2(0.0, 0.0));

	/*
	 * Chmurki
	 */
	vec4 layer = texture2D(tex_cloud1, _texture*2);
	vec4 layer2 = texture2D(tex_cloud1, _texture * 4);

	vec4 cloud = layer * layer2;

	cloud.a = cloud.r;

	cloud.r = 1.0;
	cloud.g = 1.0;
	cloud.b = 1.0;

	//jeżeli za visualRange
	cloud.a = cloud.a * min(max((env_visualRange - dist) / env_fogLength, 0.0), 1.0);

	/*
	 * Niebo właściwe
	 */
	vec4 sky = vec4(mix(env_skyColor1, env_skyColor2, dist), 1.0);

	gl_FragColor = sky * cloud;// + vec4(0.0, 0.2, 0.4, 1.0);
}
